package jface;

import jface.util.OpenDirectoryAction;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

public class JFaceActionExample extends ApplicationWindow {
	
	private OpenDirectoryAction openDirectoryAction;

	public JFaceActionExample() {
		super(null);
		openDirectoryAction = new OpenDirectoryAction();
		this.addMenuBar();
		this.addStatusLine();
		this.addToolBar(SWT.FLAT | SWT.WRAP);
	}

	protected MenuManager createMenuManager() {
		MenuManager menuBar = new MenuManager("");
		MenuManager fileMenu = new MenuManager("&File");
		MenuManager helpMenu = new MenuManager("&Help");
		menuBar.add(fileMenu);
		menuBar.add(helpMenu);
		fileMenu.add(openDirectoryAction);
		return menuBar;
	}

	protected ToolBarManager createToolBarManager(int style) {
		ToolBarManager toolBarManager = new ToolBarManager(style);
		toolBarManager.add(new Action(){@Override
			public String getText() {
				return "Save";
			}});
		toolBarManager.add(new Action(){@Override
			public String getText() {
				return "Copy";
			}});
		toolBarManager.add(new Action(){@Override
			public String getText() {
				return "Exit";
			}});
		toolBarManager.add(openDirectoryAction);
		return toolBarManager;
	}
	
	protected Control createContents(Composite parent) {
		getShell().setText("Action Example");
		setStatus("Example running...");
		return parent;
	}

	protected StatusLineManager createStatusLineManager() {
		StatusLineManager slm = new StatusLineManager();
		return slm;
	}

	public static void main(String[] args) {
		JFaceActionExample fe = new JFaceActionExample();
		fe.setBlockOnOpen(true);
		fe.open();
		Display.getCurrent().dispose();
	}
}